/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import Dao.DisciplinaDao;
import Dao.DisciplinaDaoImplJPA;
import Dao.ProfessorDao;
import Dao.ProfessorDaoImplJPA;
import Dao.TurmaDao;
import Dao.TurmaDaoImplJPA;
import Pojo.Disciplina;
import Pojo.Turma;
import Pojo.Professor;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author maione
 */
public class TurmaDaoImplJPATeste {
    
    public TurmaDaoImplJPATeste() {
    }
    
    @BeforeClass
    public static void setUpClass() {
    }
    
    @AfterClass
    public static void tearDownClass() {
    }
    
    @Before
    public void setUp() {
    }
    
    @After
    public void tearDown() {
    }
    // TODO add test methods here.
    // The methods must be annotated with annotation @Test. For example:
    //
    // @Test
    // public void hello() {}
    
    @Test
    public void inserirDaCerto(){
        TurmaDao turmaDao = new TurmaDaoImplJPA();
        Turma turma = new Turma(1,1992, 13, "ctan","4-6",60,false);
        assertTrue(turmaDao.inserir(turma));
    }
           
    @Test
    public void alterarDaCerto(){
        TurmaDao turmaDao = new TurmaDaoImplJPA();
        Turma turma = new Turma(1,1992, 13, "ctan","4-6",50,false);
        assertTrue(turmaDao.alterar(turma));
    }
    
    @Test
    public void alterarDaErrado(){
        TurmaDao turmaDao = new TurmaDaoImplJPA();
        Turma turma = new Turma(4,1992, 13, "ctan","4-6",50,false);
        assertFalse(turmaDao.alterar(turma));
    }
    
    @Test
    public void removerDaCerto(){
        TurmaDao turmaDao = new TurmaDaoImplJPA();
        Turma turma = new Turma(1,1992, 13, "ctan","4-6",60,false);
        assertTrue(turmaDao.remover(turma));
    }
    
    @Test
    public void removerDaErrado(){
        TurmaDao turmaDao = new TurmaDaoImplJPA();
        Turma turma = new Turma(22,1992, 13, "ctan","4-6",60,false);
        assertFalse(turmaDao.remover(turma));
    }
    
    @Test
    public void pesquisarPorProfessorDaCerto(){
        TurmaDao turmaDao = new TurmaDaoImplJPA();
        ProfessorDao professorDao = new ProfessorDaoImplJPA();
        Professor professor = new Professor(1,"Silvestre", "09823456434", "dcomp");
        professorDao.inserir(professor);
        Turma turma = new Turma(1992, 2, "ctan","4-6",60,false,professor,null,null,null);
        turmaDao.inserir(turma);
        assertNotSame(0,turmaDao.pesquisarPorProfessor(professor).size());
    }
    
    @Test
    public void pesquisarPorProfessorDaErrado(){
        TurmaDao turmaDao = new TurmaDaoImplJPA();
        Professor professor = new Professor(5,"Daniel Madeira", "82734567343", "dcomp");
        assertSame(0,turmaDao.pesquisarPorProfessor(professor).size());
    }
    
    @Test
    public void pesquisarPorDisciplinaAnoPeriodoDaCerto(){
        TurmaDao turmaDao = new TurmaDaoImplJPA();
        DisciplinaDao disciplinaDao = new DisciplinaDaoImplJPA();
        Disciplina disciplina = new Disciplina(1, "AEDS", "algoritmos", 72);
        disciplinaDao.inserir(disciplina);
        Turma turma = new Turma(1992, 2, "ctan","4-6",60,false,null,disciplina,null,null);
        turmaDao.inserir(turma);
        assertNotSame(0,turmaDao.pesquisarPorDisciplinaAnoPeriodo(disciplina,1992,2).size());
    }
    
   @Test
    public void pesquisarPorDisciplinaAnoPeriodoDaErrado(){
        TurmaDao turmaDao = new TurmaDaoImplJPA();
        Disciplina disciplina = new Disciplina(20, "AEDS", "algoritmos", 72);
        assertSame(0,turmaDao.pesquisarPorDisciplinaAnoPeriodo(disciplina,2000,6).size());
    }
   
    @Test
    public void pesquisarPorIdDaCerto(){
        TurmaDao turmaDao = new TurmaDaoImplJPA();
        assertNotNull(turmaDao.pesquisarPorId(4));
    }
 
}